<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>管理员管理</title>
    <link type="text/css" rel="stylesheet" th:href="@{/css/page.css}"/>
    <script type="text/javascript" th:src="@{/js/jquery/jquery-3.3.1.js}"></script>
    <!-- mmGrid -->
    <link rel="stylesheet" type="text/css" th:href="@{/plug/mmGrid/mmGrid.css}"/>
    <script type="text/javascript" th:src="@{/plug/mmGrid/mmGrid.js}"></script>
    <!-- mmGrid page -->
    <link rel="stylesheet" type="text/css" th:href="@{/plug/mmGrid/mmPaginator.css}"/>
    <script type="text/javascript" th:src="@{/plug/mmGrid/mmPaginator.js}"></script>

    <!-- layer -->
    <link type="text/css" rel="stylesheet" th:href="@{/plug/layui/css/layui.css}" media="all"/>
    <script type="text/javascript" th:src="@{/plug/layui/layui.js}" charset="utf-8"></script>

    <link type="text/css" rel="stylesheet" th:href="@{/js/layer/skin/layer.css}"/>
    <script type="text/javascript" th:src="@{/js/layer/layer.js}"></script>
    <style type="text/css">
    </style>

</head>
<body>
<div lay-allowclose="true" style="margin-left:15px; width: 98%">
    <div class="first_div" style="border:none;">
        <table class="param_table" style="margin-left:10px;">
            <tr>
                <td style="width:150px;">
                    <span>姓名：</span>
                    <input type="text" id="name" name="name" class="input_0"/>
                </td>

                <td style="">
                    <div class="layui-btn-group">
                        <button class="layui-btn" style="background-color: #a8adcc;" onclick="search()">查询</button>
                        <button class="layui-btn" style="background-color: #a8adcc;" onclick="addRow()">增加医护人员
                        </button>
                    </div>
                </td>
            </tr>
        </table>

        <div style="margin:3px 10px 10px 10px;"></div>
        <div id="exampleTableUser" style="margin-top:5px;"></div>
        <div id="paginator11-1" align="right" style="margin-right:10px;"></div>
    </div>
</div>
</body>
</html>

<script type="text/javascript">
    $(function () {
        //表格
        $('#exampleTableUser').mmGrid({
            root: 'rows',// 和后台数据保存列一致,对应MMGridPageVoBean rows
            url: "/admin/getAllUserByLimit",
            width: 'auto',
            height: 'auto',
            //checkCol: true,
            fullWidthRows: true, //表格第一次加载数据时列伸展，自动充满表格
            showBackboard: false,
            //multiSelect: true,
            indexCol: true,  //索引列
            params: function () {
                var param = new Object();
                param.name = $.trim($("#name").val());
                return param;
            },
            cols: [{title: 'ID', name: 'id', width: 60, hidden: true},
                {title: '姓名', name: 'name', width: 50},
                {title: '身份证号', name: 'idCard', width: 120},
                {title: '移动电话', name: 'phone', width: 60},
                {title: '职位', name: 'department', width: 50},
                {title: '医院名', name: 'hospitalName', width: 120},
                {title: '地址', name: 'address', width: 120},
                {
                    title: '操作', name: 'id', width: 80, renderer: function (val, item, rowIndex) {
                        var buttonStr = '<span class=" layui-btn layui-btn-danger layui-btn-sm" onclick="deleteRowOne(' + "\'" + item.id + "\'" + ')" >删除</span>';
                        return "<div class='span_btus' >" + buttonStr + "</div>";
                    }
                }
            ],
            plugins: [
                $('#paginator11-1').mmPaginator({
                    totalCountName: 'total',    //对应MMGridPageVoBean count
                    page: 1,                    //初始页
                    pageParamName: 'page',      //当前页数
                    limitParamName: 'limit', //每页数量
                    limitList: [10, 20, 30, 50]
                })
            ]
        });
    });

    //查询
    function search() {
        $('#exampleTableUser').mmGrid().load({"page": 1});
    }

    //删除一行
    function deleteRowOne(id) {
        layer.confirm('确认删除吗？', {icon: 3, title: '提示'}, function (index) {
            var param = [];
            param.push({"name": "ids", "value": id});
            $.ajax({
                type: "POST",
                async: true,  //默认true,异步
                data: param,
                url: "/admin/delUser",
                success: function (data) {
                    if (data == "SUCCESS") {
                        layer.alert('删除成功！', {icon: 1}, function (indexOk) {
                            search();
                            layer.close(indexOk);
                        });
                    } else if (data == "DontOP") {
                        layer.alert('删除失败！自己不能删除自己！', {icon: 2}, function (indexNo) {
                            layer.close(indexNo);
                        });
                    } else {
                        layer.alert('删除失败！', {icon: 2}, function (indexNo) {
                            layer.close(indexNo);
                        });
                    }
                }
            });
        });
    }

    //增加用户
    function addRow() {
        layer.open({
            type: 2,
            title: '增加用户',
            area: ['55%', '90%'],//宽高
            content: '/admin/addUserPage' //iframe的url
        });
    }

    //修改标签
    function editRowOne(id) {
        layer.open({
            type: 2,
            title: '修改用户',
            area: ['70%', '90%'],
            content: '/admin/addUserPage?userId=' + id //iframe的url
        });
    }

    //导入用户表格
    function importUser() {
        layer.open({
            type: 2,
            title: '增加用户',
            area: ['70%', '90%'],
            content: '/admin/importUser' //iframe的url
        });
    }

</script>